﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace TSCL.Web.menu
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(id);
				}
			}
		}
			
	private void ShowInfo(int id)
	{
		TSCL.BLL.menu bll=new TSCL.BLL.menu();
		TSCL.Model.menu model=bll.GetModel(id);
		this.lblid.Text=model.id.ToString();
		this.txtpid.Text=model.pid.ToString();
		this.txtmenuname.Text=model.menuname;
		this.txtmenulink.Text=model.menulink;
		this.txtmenuorder.Text=model.menuorder.ToString();
		this.txtmenulevel.Text=model.menulevel.ToString();
		this.txtremarks.Text=model.remarks;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtpid.Text))
			{
				strErr+="pid格式错误！\\n";	
			}
			if(this.txtmenuname.Text.Trim().Length==0)
			{
				strErr+="menuname不能为空！\\n";	
			}
			if(this.txtmenulink.Text.Trim().Length==0)
			{
				strErr+="menulink不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtmenuorder.Text))
			{
				strErr+="menuorder格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtmenulevel.Text))
			{
				strErr+="menulevel格式错误！\\n";	
			}
			if(this.txtremarks.Text.Trim().Length==0)
			{
				strErr+="remarks不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int id=int.Parse(this.lblid.Text);
			int pid=int.Parse(this.txtpid.Text);
			string menuname=this.txtmenuname.Text;
			string menulink=this.txtmenulink.Text;
			int menuorder=int.Parse(this.txtmenuorder.Text);
			int menulevel=int.Parse(this.txtmenulevel.Text);
			string remarks=this.txtremarks.Text;


			TSCL.Model.menu model=new TSCL.Model.menu();
			model.id=id;
			model.pid=pid;
			model.menuname=menuname;
			model.menulink=menulink;
			model.menuorder=menuorder;
			model.menulevel=menulevel;
			model.remarks=remarks;

			TSCL.BLL.menu bll=new TSCL.BLL.menu();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
